package com.zh.note.demo.io;

import java.io.*;
import java.nio.channels.FileChannel;

/**
 * 使用nio复制文件
 */
public class NIODemo {
    /**
     * FileChannel + transferTo
     */
    public static void NioFileCopy(File source, File target) {
        try (FileInputStream fileInputStream = new FileInputStream(source);
             FileOutputStream fileOutputStream = new FileOutputStream(target);
             FileChannel in = fileInputStream.getChannel();
             FileChannel out = fileOutputStream.getChannel()) {
            in.transferTo(0, in.size(), out);

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        File source = new File("A.txt");
        File target = new File("B.txt");
        // NioFileCopy(source, target);

    }
}
